<?php
 require "./config/mysql.php";
 class messageList extends mysqlPdo
 {

  public static function messageinfo()

   {
        $pdo = mysqlPdo::getPdoConnect();
        $tr = $pdo -> query("select * from message");
        $str = $tr -> fetchAll(PDO::FETCH_ASSOC);
        $total =$tr -> rowCount();   //获取总记录数;
        $num = 5;             //每页显示的记录数;
        $url = "message.php";          //请求的URL 
        $cpage = isset($_GET["page"])?$_GET["page"]:1;//当前页  
        $pagenum = ceil($total/$num);//总页数 
        $offset = ($cpage-1)*$num;//开始去数据的位置  
       $sql1 = "select message.*,article_kind.id as pid,king from message left join article_kind on message.kid=article_kind.id order by message.time desc limit {$offset},{$num}";
        $tr1 = $pdo -> query($sql1);
        $str1 = $tr1 -> fetchAll(PDO::FETCH_ASSOC);
        $start = $offset+1;//开始记录页 
        $end = ($cpage==$pagenum) ? $total : ($cpage*$num);//结束记录页 
        $next = ($cpage==$pagenum) ? $pagenum : ($cpage+1);//下一页  
        $prev = ($cpage==1) ? 1 : ($cpage-1);//前一页 
        $arr = array(
            'total'=>$total,
            'num'=>$num,
            'url'=>$url,
            'cpage'=>$cpage,
            'pagenum'=>$pagenum,
            'offset'=>$offset,
            'str1'=>$str1,
            'start'=>$start,
            'end'=>$end,
            'next'=>$next,
            'prev'=>$prev,
            );
            return $arr;
   }

   public static function  delemessage($id)

 {
       $pdo = mysqlPdo::getPdoConnect();
       $tr = $pdo -> exec("delete from message where id = $id");  
       return $tr;

   }
   
}

